package com.security.lambda.comparator;

import java.util.*;

/**
 * ${DESCRIPTION}
 *
 * @author roger
 * @email 190642964@qq.com
 * @create 2017-11-09 14:37
 **/
public class Main {

    public static void main(String[] args) {


        // 排序第一种方式 lambda
        Comparator<ComEntity> comEntityComparator = (ComEntity c1, ComEntity c2) -> c1.getWeight().compareTo(c2.getWeight());

        List<ComEntity> list = new ArrayList<>();
        list.add(new ComEntity("苹果", 5));
        list.add(new ComEntity("西瓜", 15));
        list.add(new ComEntity("芒果", 10));

        Collections.sort(list, comEntityComparator);

        list.stream().forEach(l -> System.out.println(l));

        list.add(new ComEntity("橙子", 7));
        // 排序第二种方式  方法引用
        Collections.sort(list, Comparator.comparing(ComEntity::getWeight));

        list.stream().forEach(l -> System.out.println(l));

        List<String> stringList = Arrays.asList("orange", "banana", "apple", "mango");

        // 排序第二种方式  方法引用
        Collections.sort(stringList, String::compareToIgnoreCase);

        stringList.stream().forEach(string -> System.out.println(string));
    }

}
